package com.epam.command.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.command.logic.Command;
import com.epam.command.logic.ManagerLogic;
import com.epam.dao.DAOFactory;
import com.epam.dao.DAOFactory.DAOType;
import com.epam.dao.intf.DAO;
import com.epam.entity.Hotel;
import com.epam.entity.TouristVoucher;
import com.epam.entity.TouristVoucher.Country;
import com.epam.entity.TouristVoucher.Transport;
import com.epam.entity.TouristVoucher.Type;
import com.epam.util.ConfigurationManager;

public class CreateTouristVoucherCommand implements Command {
	
	
	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		DAO hoteldao = DAOFactory.INSTANCE.getDAO(DAOType.HOTEL);
		String page = ConfigurationManager.getConfig(ConfigurationManager.OPERATION_SUCCESSFUL);;
		
		Country country = Enum.valueOf(TouristVoucher.Country.class,
				request.getParameter("country"));
		int duration = Integer.parseInt(request.getParameter("duration"));
		Type type = Enum.valueOf(TouristVoucher.Type.class,
				request.getParameter("type"));
		Transport transport = Enum.valueOf(TouristVoucher.Transport.class,
				request.getParameter("transport"));
		Hotel hotel = (Hotel) hoteldao.findByID(Integer.parseInt(request
				.getParameter("hotel")));
		int cost = Integer.parseInt(request.getParameter("cost"));
		boolean lastMinute = Boolean.parseBoolean(request
				.getParameter("lastMinute"));
	
		ManagerLogic.createTouristVoucher(country, duration, type, transport, hotel, cost, lastMinute);
		
		request.setAttribute("message", "Voucher created successfully");
		
		return page;
		
	}

}
